/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import java.io.IOException;
import java.io.Serializable;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import com.gesturn2.comercio.Servicio;


/**
 *
 * @author Man
 */
public class RegistrarServicioAction extends Action implements Serializable {

    String next = "";
    HttpSession session = null;//request.getSession(true);
    
   

    @Override



    public void run() throws ServletException, IOException {
           
           Servicio clie = new Servicio();
        // Obtener los parametros
        clie.setCodigo((request.getParameter("campoId")));
        clie.setNombre(request.getParameter("campoNombre"));
        clie.setValor(Double.parseDouble(request.getParameter("campoValor")));
        clie.setDescripcion(request.getParameter("campoDescripcion"));

       try{
     	  model.agregarServicio(clie);
     	}catch(Exception ex){
     	   throw new ServletException("Error al agregar Servicio: "+ex);
	}
         next = "/index.jsp";

         
        RequestDispatcher rd = application.getRequestDispatcher(next);
        if (rd == null) {
            throw new ServletException("No se pudo encontrar " + next);
        }
        rd.forward(request, response);


    }

}
